<?php
/**
 * @package		Joomla.Site
 * @subpackage	com_content
 * @copyright	Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

// no direct access
defined('_JEXEC') or die;

jimport('joomla.application.component.helper');
jimport('joomla.application.categories');

/**
 * Content Component Route Helper
 *
 * @static
 * @package		Joomla.Site
 * @subpackage	com_content
 * @since 1.5
 */
abstract class ContentHelperCnsolution
{       
    public static function getDataSlide($catid_slide)
    {
        $db = JFactory::getDbo();
        $query = "
            SELECT c.id, c.catid, c.images, c.alias, c.language 
                FROM cn_content as c 
                    WHERE c.catid = ".$catid_slide." AND c.state = 1    
        ";
        
        $db->setQuery($query);
        $data = $db->loadObjectList();
        return $data;
    }
    
    public static function getHomeAticles($catid_home)
    {
        $db = JFactory::getDbo();
        $query = "
            SELECT c.id, c.catid, c.title, c.introtext as content, c.language, c.alias 
                FROM cn_content as c 
                    WHERE c.catid = ".$catid_home." AND c.state = 1 
        ";
        $db->setQuery($query);
        $data = $db->loadObjectList();
        return $data;
    }
    
    public static function truncateDataFilter($message,$length)
    {
     $message = trim($message);
     $words = explode(" ",$message);
     if (count($words) > $length)
     {
        $words = array_slice($words, 0, $length);
        $message = implode(" ", $words).' ...';
     }
     return $message;
    }
    
    public static function getNameOfSubCat($catid)
    {
        $db = JFactory::getDbo();
        $query = "
            SELECT c.title
                FROM cn_categories as c
                    WHERE c.parent_id = ".$catid."
        ";
        $db->setQuery($query);
        $data = $db->loadObjectList();
        return $data;
    }
    
    public static function getDataByCatId($catid)
    {
        $db = JFactory::getDbo();
        $query = "
        SELECT c.id, c.catid, c.title, c.introtext as content, c.language, c.alias, c.images 
            FROM cn_content as c
                WHERE c.catid IN (SELECT id FROM cn_categories WHERE parent_id = ".$catid.")
        ";
        $db->setQuery($query);
        $data = $db->loadObjectList();
        return $data;
    }
    
    public static function getNameOfCatFromCatID($catid)
    {
        $db = JFactory::getDbo();
        $query = "
        SELECT c.title 
            FROM cn_categories as c
                WHERE c.id = ".$catid."
        ";
        $db->setQuery($query);
        $data = $db->loadResult();
        return $data;
    }
    
}
